<!DOCTYPE html>
<html>
<head>
<include file="Include:meta" />
<title>休息-目的地运营集团数据管理平台</title>
<include file="Include:style" />
<link rel="stylesheet" href="__PUBLIC__/mobile/css/mobiscroll.min.css">
</head>
<body>
<div class="schedule_add">
	<div class="header">
		<a class="back_btn" href="javascript:history.back(-1);"></a>
		<if condition="$data eq NULL">添加<else/>编辑</if>日程
	</div>
	<include file="Include:commu_menu" />
	<div class="schedule_add_title">
		<img class="det_bg" src="__PUBLIC__/mobile/images/index/xx_bg.jpg">
		<div class="txt">
			<img src="__PUBLIC__/mobile/images/index/tit_icon3.png">
			<span>休 息</span>
			<p><if condition="$end eq NULL">{$start}<else/>{$start} 至 {$end}</if></p>
		</div>
	</div>
	<div class="btn_box xx text_c">
		<foreach name="fill_post" item="vo">
			<a href="javascript:void(0)" fill_post="{$vo['name1']}" <if condition="$data['fill_post'] eq $vo['name1']">class="active"</if>>{$vo['name2']}</a>
		</foreach>
	</div>
	<div class="inp_list all">
		<ul>
			<li>
				<if condition="$data['noedit'] neq 1">
					<if condition="$data neq NULL">
						<if condition="$data['status'] eq -1">
							<select name="pid" id="md-country" required data-icon="location">
								<option value="-10">请选择项目编号</option>
								<foreach name="plist" item="vo">
									<option value="{$vo['id']}" <if condition="$data['pid'] eq $vo['id']">selected</if>>[{$vo['project_num']}]{$vo['project_name']}</option>
								</foreach>
							</select>
						<else/>
							[{$data['project_num']}]{$data['project_name']}
						</if>
					<else/>
						<select name="pid" id="md-country" required data-icon="location">
							<option value="-10">请选择项目编号</option>
							<foreach name="plist" item="vo">
								<option value="{$vo['id']}">[{$vo['project_num']}]{$vo['project_name']}</option>
							</foreach>
						</select>
					</if>
					<span class="error-item">必填项</span>
				<else/>
					[{$data['project_num']}]{$data['project_name']}
				</if>
			</li>
			<if condition="$data['noedit'] neq 1">
				<if condition="$data neq NULL">
					<if condition="$data['agent_post'] neq NULL">
						<li class="change">
							<if condition="$users eq NULL">
								<!-- 显示输入的人员 无项目人员-->
								<input class="required-text" name="agent_name" type="text" readonly placeholder="请选择代理人" value="{$data['agent']}">
							<else/>
								<!-- 显示输入的人员 有项目人员-->
								<input class="required-text" name="agent_name" type="text" readonly placeholder="请选择代理人" value="{$data['agent']}">
							</if>
						</li>
					<else/>
						<li class="change">
							<!-- 显示选择的项目人员 -->
							<input class="required-text" name="agent_name" type="text" readonly="" placeholder="请选择代理人" fid="{$data['agent']}" value="{$data['agent_name']}">
						</li>
					</if>
				<else/>
					<li class="change" style="display:none">
						<input class="required-text" name="agent_name" type="text" readonly placeholder="请选择代理人">
					</li>
				</if>
			<else/>
				<li class="change">
					<if condition="$data['agent_post'] eq NULL">{$data['agent_name']}<else/>{$data['agent']}</if>
				</li>
			</if>
			<if condition="$data['noedit'] neq 1">
				<if condition="$data neq NULL">
					<li class="change">
						<if condition="$data['agent_post'] neq NULL">
							<!-- 显示输入的人员职务-->
							<input class="required-text" name="agent_post" type="text" placeholder="请填写代理人职务" value="{$data['agent_post']}">
						<else/>
							<!-- 显示选择的项目人员职务-->
							<input class="required-text" name="agent_post" type="text" readonly="" placeholder="请选择代理人" value="{$data['position']}" readonly>
						</if>
					</li>
				<else/>
					<li class="change" style="display:none">
						<input class="required-text" name="agent_post" type="text" placeholder="请填写代理人职务">
					</li>
				</if>
			<else/>
				<li class="change">
					<if condition="$data['agent_post'] eq NULL">{$data['position']}<else/>{$data['agent_post']}</if>
				</li>
			</if>
			<if condition="$data['noedit'] neq 1">
				<if condition="$data neq NULL">
					<li class="change">
						<if condition="$data['agent_post'] neq NULL">
							<!-- 显示输入的人员手机-->
							<input class="required-text" name="agent_tel" type="text" placeholder="请填写代理人手机号" value="{$data['agent_tel']}">
						<else/>
							<!-- 显示选择的项目人员手机-->
							<input class="required-text" name="agent_tel" type="text" placeholder="请填写代理人手机号" readonly="readonly" value="{$data['mobilephone']}">
						</if>
						<p class="error-item">请填写正确的手机号</p>
					</li>
				<else/>
					<li class="change" style="display:none">
						<input class="required-text" name="agent_tel" type="text" placeholder="请填写代理人手机号">
						<p class="error-item">请填写正确的手机号</p>
					</li>
				</if>
			<else/>
				<li class="change">
					<if condition="$data['agent_post'] eq NULL">{$data['mobilephone']}<else/>{$data['agent_tel']}</if>
				</li>
			</if>
		</ul>
	</div>
	<div class="build_btn paddbox"><div><button type="button" class="sub_btn disabled xx" disabled>保 存</button></div></div>
	<input class="hide_inp" type="hidden" start="{$start}" end="{$end}" ttype="{$type}" cur="">
</div>
<!-- 弹出框 -->
<div class="Alert operate_alert bg_alert">
    <div>
        <textarea name="hb_text" maxlength="4"><if condition="$data['agent_post'] neq NULL">{$data['agent']}</if></textarea>
        <div class="tab_box mb10">
            <foreach name="users" item="vo">
				<a href="javascript:;" fid="{$vo['id']}" zw="{$vo['position']}" phone="{$vo['mobilephone']}">{$vo['username']}</a>
			</foreach>
        </div>
        <div class="btn_box clearboth">
            <a class="btn_close float_l" href="javascript:;">取消</a><button class="btn_alert float_r disabled" disabled>确定</button>
        </div>
        <input class="size_input" type="hidden" sid="" tid="">
    </div>
</div>
<include file="Include:javascript" />
<script src="__PUBLIC__/mobile/js/mobiscroll.min.js"></script>
<script>
    $(function(){
		$("[name='pid']").change(function(){
			if($(this).val()==-10){
				$('.inp_list .change').hide();
			}else{
				$('.required-text').val('');
				var val = $(this).find('option:selected').val(),
					start = $('.hide_inp').attr('start'),
					end = $('.hide_inp').attr('end');
				$.ajax({
					type:"POST",
					async:false,
					dataType:"json",
					data:{"id":val,"start":start,"end":end,"action":"user"},
					url:"__APP__/Mobile/Index/schedule_list_ajax",
					success : function (data) {
						var html = '';
						for(var i=0;i<data.length;i++){
							html+= "<a href='javascript:;' fid='"+data[i].id+"' zw='"+data[i].position+"' phone='"+data[i].mobilephone+"'>"+data[i].username+"</a>";
						}
						$('.tab_box').html(html);
						$('.inp_list .change').show();
					}
				})
			}
		})
		$("[name='agent_name']").click(function(){
			var val = $(this).val();
            Mask();
			$('.operate_alert').fadeIn().find('textarea').focus();
			if($("[name='hb_text']").val()!=''){
				$(".btn_alert").removeClass("disabled").attr('disabled',false);
			}
        })
        $('body').on('click','.tab_box a',function(){
            var txt = $(this).text(),
                fid = $(this).attr('fid'),
				zw = $(this).attr('zw'),
				phone = $(this).attr('phone');
            $("[name='agent_name']").val(txt).attr('fid',fid);
            $('.Mask').fadeOut(function(){
                $(this).remove();
            });
            $('.operate_alert').fadeOut();
			$("[name='hb_text']").val('');
			$("[name='agent_post']").val(zw).attr('readonly',true);
			$("[name='agent_tel']").val(phone).attr('readonly',true);
			$(".btn_alert").addClass("disabled").attr('disabled',true);
			$('.hide_inp').attr('cur','2');
			submit();
        })
        $("[name='hb_text']").bind('input propertychange', function() {  
            var val = $(this).val();
            if(val!=''){
                $(".btn_alert").removeClass("disabled").attr('disabled',false);
            }else{
                $(".btn_alert").addClass("disabled").attr('disabled',true);
            }
        })
        $(".btn_alert").click(function(){
            var txt = $("[name='hb_text']").val();
            $("[name='agent_name']").val(txt).attr('fname',txt);
            $('.Mask').fadeOut(function(){
                $(this).remove();
            });
            $('.operate_alert').fadeOut();
			$("[name='agent_post']").val('').attr('readonly',false);
			$("[name='agent_tel']").val('').attr('readonly',false);
			submit();
			$('.hide_inp').attr('cur','1');
        })
		$('.btn_close').click(function(){
			$("[name='hb_text']").val('');
			$(".btn_alert").addClass("disabled").attr('disabled',true);
		})
		//
		$('.btn_box a').click(function(){
			$(this).addClass('active').siblings().removeClass('active');
		})
		$('#md-country').mobiscroll().select({
			theme: 'ios',
			display: 'bottom',
			placeholder: 'Country',
			lang: 'zh'
		});
		submit();
		$('.btn_box a').click(function(){
			submit();
		})
		$('#md-country').change(function(){
			submit();
			$("[name='hb_text']").val('');
		})
		$('.required-text').blur(function(){
			submit();
		})
		$('.required-text').focus(function(){
			$(this).next('.error-item').hide();
		})
		//提交
		function submit(){
            var tag = true;
			
			if($('.btn_box .active').length<1){
				tag = false;
                $('.sub_btn').addClass('disabled').attr('disabled',true);
			}
            if($('#md-country').val()==-10){
                tag = false;
                $('.sub_btn').addClass('disabled').attr('disabled',true);
            }
			$('.required-text').each(function(){
				if($(this).val()==''){
					tag = false;
					$('.sub_btn').addClass('disabled').attr('disabled',true);
				}
			})
			$("[name='agent_tel']").each(function(){
				var $val = $(this).val();
				if($val!="" && !/^1[3|4|5|7|8]\d{9}$/.test($val)){
					tag = false;
					$(this).next('.error-item').show();
					$('.sub_btn').addClass('disabled').attr('disabled',true);
				}
			});
            if(tag){
                $('.sub_btn').removeClass('disabled').attr('disabled',false);
            }
        }
		$('.sub_btn').click(function(){
			var val1 = $('#md-country').val(),
				val2 = $("[name='agent_name']").attr('fid'),
				val3 = $("[name='agent_post']").val(),
				val4 = $("[name='agent_tel']").val(),
				val5 = $("[name='agent_name']").val(),
				active = $('.btn_box .active').attr('fill_post'),
				start = $('.hide_inp').attr('start'),
				end = $('.hide_inp').attr('end'),
				type = $('.hide_inp').attr('ttype'),
				cur = $('.hide_inp').attr('cur'),
				id = "{$data['id']}";
			if(id){
				if(cur==1){
					$.ajax({
						type:"POST",
						async:false,
						dataType:"json",
						data:{"pid":val1,"agent_name":val5,"agent_post":val3,"agent_tel":val4,"fill_post":active,"id":id},
						url:"__APP__/Mobile/Index/schedule_list_doedit",
						success : function (data) {
							success_pop(data['status'],data['msg'],1,'__APP__/Mobile/Index/schedule_list');
						}
					})
				}else{
					$.ajax({
						type:"POST",
						async:false,
						dataType:"json",
						data:{"pid":val1,"agent":val2,"fill_post":active,"id":id},
						url:"__APP__/Mobile/Index/schedule_list_doedit",
						success : function (data) {
							success_pop(data['status'],data['msg'],1,'__APP__/Mobile/Index/schedule_list');
						}
					})
				}
			}else{
				if(cur==1){
					$.ajax({
						type:"POST",
						async:false,
						dataType:"json",
						data:{"pid":val1,"agent_name":val5,"agent_post":val3,"agent_tel":val4,"fill_post":active,"start":start,"end":end,"type":type},
						url:"__APP__/Mobile/Index/schedule_list_doadd",
						success : function (data) {
							success_pop(data['status'],data['msg'],1,'__APP__/Mobile/Index/schedule_list');
						}
					})
				}else{
					$.ajax({
						type:"POST",
						async:false,
						dataType:"json",
						data:{"pid":val1,"agent":val2,"fill_post":active,"start":start,"end":end,"type":type},
						url:"__APP__/Mobile/Index/schedule_list_doadd",
						success : function (data) {
							success_pop(data['status'],data['msg'],1,'__APP__/Mobile/Index/schedule_list');
						}
					})
				}
			}
		})
    })
</script>
</body>
</html>